﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PentaBiz.Collections.DataCache;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            //create initial items
            var list = new List<Data> { new Data { Index = 0 }, new Data { Index = 1 } };

            //create temporary Sequential Data cache from the list
            using (var c = list.ToSequentialDataCache())
            {
                var sw = new Stopwatch();
                sw.Start();
                for (int i = 2; i < 30000; i++)
                {
                    c.Add(new Data { Index = i });
                }
                sw.Stop();
                Console.WriteLine("Added 30000 in {0}",sw.Elapsed);

                sw.Restart();
                //do some calculations
                var average = c.Average(data => data.Index);
                sw.Stop();
                Console.WriteLine("Average:{0}", average);
                Console.WriteLine("Calculated average of 30000 in {0}", sw.Elapsed);

                sw.Restart();
                //do some calculations
                var sum = c.Sum(data => data.Index);
                sw.Stop();
                Console.WriteLine("Sum:{0}", sum);
                Console.WriteLine("Calculated sum of 30000 in {0}", sw.Elapsed);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();


        }

        [Serializable]
        class Data
        {
            public int Index { get; set; }
        }
    }
}
